<?php

namespace App\Notifications;

use App\Models\Reply;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;

class PostReplied extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public function __construct(
        public Reply $reply,
        public User $replier
    ) {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['database'];
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'reply_id' => $this->reply->id,
            'reply_content' => \Str::limit($this->reply->content, 100),
            'replier_id' => $this->replier->id,
            'replier_name' => $this->replier->nickname ?? $this->replier->name,
            'replier_avatar' => $this->replier->avatar,
            'post_id' => $this->reply->post_id,
            'post_title' => $this->reply->post->title ?? '',
            'post_slug' => $this->reply->post->slug ?? '',
            'bar_id' => $this->reply->post->bar_id ?? null,
            'bar_name' => $this->reply->post->bar->name ?? '',
            'bar_slug' => $this->reply->post->bar->slug ?? '',
            'parent_reply_id' => $this->reply->parent_id,
        ];
    }
}
